<template>
  <div>
      <el-dialog
        title="提示"
        :visible.sync="dialogVisible"
        :showClose="false"
        width="98%">
        <div>
          <template>
            <el-table
              :data="tableData"
              :cell-style="{'text-align':'center'}"
            :header-cell-style="{background:'#f5f5f5','text-align':'center'}"
              border
              style="width: 100%">
              <el-table-column
                prop="itemTag"
                label="测点标识"
                >
              </el-table-column>
              <el-table-column
                prop="itemName"
                label="测点名称"
                width="120">
                <template #default="{row}">
                  <el-input size="mini" v-model="row.itemName"></el-input>
                </template>
              </el-table-column>
              <el-table-column
                prop="dataAddress"
                label="测点地址"
                width="100">
                <template #default="{row}">
                  <el-input size="mini" v-model="row.dataAddress"></el-input>
                </template>
              </el-table-column>
              <el-table-column
                prop="dataRate"
                label="倍率"
               width="80">
               <template #default="{row}">
                  <el-input size="mini" v-model="row.dataRate"></el-input>
                </template>
              </el-table-column>
              <el-table-column
                prop="name"
                label="转换公式"
                width="150"
               >
               <template #default="{row}">
                <el-select v-model="row.convertType"   clearable    size="mini" style="margin-right: 10px;" >
                  <el-option class="select" v-for="(item,index) in xlalalist" :key="index" :label="item.text" :value="item.value"></el-option>
                </el-select>
               </template>
              </el-table-column>
              <el-table-column
                prop="dataPrecision"
                label="数据精度">
                <template #default="{row}">
                  <el-input size="mini" v-model="row.dataPrecision"></el-input>
                </template>
              </el-table-column>
              <el-table-column
                prop="holdAlarm"
                label="是否实时保存"
                width="120">
               <template #default="{row}">
                <el-select v-model="row.realtimeSave"  clearable   size="mini" style="margin-right: 10px;" >
                  <el-option class="select" label="是" :value="true"></el-option>
                  <el-option class="select" label="否" :value="false"></el-option>
                </el-select>
               </template>
              </el-table-column>
              <el-table-column
                prop="holdAlarm"
                label="允许告警"
                width="100"
               >
               <template #default="{row}">
                <el-select v-model="row.enableAlarm"  clearable   size="mini" style="margin-right: 10px;" >
                  <el-option class="select" label="是" :value="true"></el-option>
                  <el-option class="select" label="否" :value="false"></el-option>
                </el-select>
               </template>
              </el-table-column>
              <el-table-column
                prop="upperThreshold"
                label="上限阈值"
                >
                <template #default="{row}">
                  <el-input size="mini" v-model="row.upperThreshold"></el-input>
                </template>
              </el-table-column>
              <el-table-column
                prop="address"
                width="130"
                label="上限事件">
                <template #default="{row}">
                <el-select v-model="row.eventType0"    clearable   size="mini" style="margin-right: 10px;" >
                  <el-option class="select" v-for="(item,index) in xlalalists" :key="index" :label="item.text" :value="+item.value"></el-option>
                </el-select>
               </template>
              </el-table-column>
              <el-table-column
                prop="lowerThreshold"
                label="下限阈值"
                >
                <template #default="{row}">
                  <el-input size="mini" v-model="row.lowerThreshold"></el-input>
                </template>
              </el-table-column>
              <el-table-column
                prop="eventType1"
                label="下限事件"
                width="130"
                >
                <template #default="{row}">
                <el-select v-model="row.eventType1"   clearable    size="mini" style="margin-right: 10px;" >
                  <el-option class="select" v-for="(item,index) in xlalalists" :key="index" :label="item.text" :value="+item.value"></el-option>
                </el-select>
               </template>
              </el-table-column>
              <el-table-column
                prop="uppestThreshold"
                label="上上限阈值">
                <template #default="{row}">
                  <el-input size="mini" v-model="row.uppestThreshold"></el-input>
                </template>
              </el-table-column>
              <el-table-column
                prop="eventType2"
                label="上上限事件"
                width="130"
                >
                <template #default="{row}">
                <el-select v-model="row.eventType2"    clearable   size="mini" style="margin-right: 10px;" >
                  <el-option class="select" v-for="(item,index) in xlalalists" :key="index" :label="item.text" :value="+item.value"></el-option>
                </el-select>
               </template>
              </el-table-column>
              <el-table-column
                prop="lowestThreshold"
                label="下下限阈值"
                >
                <template #default="{row}">
                  <el-input size="mini" v-model="row.lowestThreshold"></el-input>
                </template>
              </el-table-column>
              <el-table-column
                prop="eventType3"
                width="130"
                label="下下限事件">
                <template #default="{row}">
                <el-select v-model="row.eventType3"  clearable     size="mini" style="margin-right: 10px;" >
                  <el-option class="select" v-for="(item,index) in xlalalists" :key="index" :label="item.text" :value="+item.value"></el-option>
                </el-select>
               </template>
              </el-table-column>
            </el-table>
          </template>
    </div>
        <span  class="dialog">
          <button class="button" type="primary" @click="submit" style=" cursor: pointer;">确 定</button>
          <button @click="dialogVisible = false" style=" cursor: pointer;">取 消</button>
        </span>
      </el-dialog>
  </div>
</template>

<script>
import { getpicedianlistapi, getyaocexialaapi, postpiliangputapi, postpixiucedianapi } from '@/api/measure'
import { putpiliangapi } from '@/api/device'
import { getguizelistapi } from '@/api/eventtype'
export default {
  name: 'MaintenanceYaoce',
  props: {
    changeselect: {
      type: Array
    },
    flag: {
      type: String
    }
  },
  data () {
    return {
      tableData: [],
      dialogVisible: false,
      xlalalist: [],
      xlalalists: []
    }
  },

  async mounted () {
    const res = await getguizelistapi()
    this.xlalalist = res.data.list
    const ress = await getyaocexialaapi()
    this.xlalalists = ress.data.list
  },

  methods: {
    async getgetpicedianlist () {
      const arr = this.changeselect.map(ele => ele.id)
      if (this.flag) {
        const res = await postpixiucedianapi(arr)
        this.tableData = res.data.list
      } else {
        const res = await getpicedianlistapi(arr)
        this.tableData = res.data.list
      }
    },
    async submit () {
      if (this.flag) {
        await putpiliangapi(this.tableData)
      } else {
        await postpiliangputapi(this.tableData)
      }

      this.dialogVisible = false
      this.$message.success('修改成功')
      this.$emit('shuxing')
    }
  },
  watch: {
    dialogVisible (val) {
      if (val) {
        this.getgetpicedianlist()
      }
    }
  }
}
</script>

<style lang="scss" scoped>
.dialog{
  display: inline-block;
  margin: 0 auto;
  width: 100%;
  text-align: center;
  margin-top: 10px;
}
.dialog button{
  width:70px;
  height:30px;
  background-color:#fff;
  border-radius:5px;
  border:1px solid #ccc;
  margin-left:5px;
}
.button{
  background-color: #169bd5 !important;
  color: #fff;
}
</style>
